package com.example.community.add;

import com.example.community.dao.PaytypeDao;
import com.example.community.model.Paytype;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/payTypeAddServlet")
public class PayTypeAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/WEB-INF/payManager/paytypeAdd.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String paytype = req.getParameter("paytype");

            Paytype paytypetab = new Paytype();
            paytypetab.setPtName(paytype);

            PaytypeDao paytypeDao = new PaytypeDao();
            Integer insert = paytypeDao.insert(paytypetab);
            if (insert == 1){
                resp.getWriter().write("true");
            }else {
                resp.getWriter().write("false");
            }
        }catch (Exception e){
            resp.getWriter().write("false");
        }

    }
}
